package cn.trda.controller;

import java.util.Date;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;

import cn.trda.pojo.Logs;
import cn.trda.pojo.User;
import cn.trda.service.LogService;

public class BaseController {
	@Autowired
	private LogService logsService;
	//返回session用户
	protected User getSessionUser(HttpSession session){
		return (User)session.getAttribute("user");
	}
	
	//记录日志
	protected void addLog(User user,String message) throws Exception{
		Logs logs = new Logs();
		logs.setUserid(user.getId());
		logs.setUsername(user.getUsercode());
		logs.setOperateinfo(message);
		logs.setOperatedatetime(new Date());
		logsService.insertLogs(logs);
	}
}
